package com.course.redis.controller;

import com.course.common.model.vo.SignInUserInfo;
import com.course.common.response.BaseResponse;
import com.course.redis.service.SignService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @PROJECT_NAME: course
 * @DESCRIPTION: 签到控制层
 * @Author: 涂玄武
 * @DATE: 2021/7/14 15:33
 */
@RestController
@RequestMapping("sign")
public class SignController extends BaseController{
    
    @Resource
    private SignService signService;

    /**
     * 获取签到次数 默认当月
     * @param access_token
     * @param date
     * @return
     */
    @GetMapping("count")
    public BaseResponse getSignCount(String access_token,String date){
        SignInUserInfo signInUserInfo = loadSignInDinerInfo(access_token);
        return new BaseResponse().success(signService.getSignCount(signInUserInfo.getId(),date));
    }

    /**
     * 获取用户签到情况，默认当月
     * @param access_token
     * @param date
     * @return
     */
    @GetMapping("getSignInfo")
    public BaseResponse getSignInfo(String access_token,String date){
        SignInUserInfo signInUserInfo = loadSignInDinerInfo(access_token);
        return new BaseResponse().success(signService.getSignInfo(signInUserInfo.getId(),date));
    }

    /**
     * 签到，可以补签
     * @param access_token
     * @param date
     * @return 返回连续签到天数
     */
    @PostMapping("sign")
    public BaseResponse sign(String access_token,
                             @RequestParam(required = false) String date){
        SignInUserInfo signInUserInfo = loadSignInDinerInfo(access_token);
        return new BaseResponse().success(signService.doSign(signInUserInfo.getId(), date));
    }
    
}
